/**
 * Created by zhout on 2017/7/4.
 */
var infoVm=new Vue({
    el: '#own-info',
    data: {
        EmployeeDetail:{},
        telephone:'',
        email:'',
        idCard:''
    },
    methods:{
        /**
         * 获取员工详情
         * @constructor
         */
        GetEmployeeDetail:function () {
            if(isLogin()){
                if(!isLoginLose()){
                    var config = {
                        url: httpURL + "el/employee/find",
                        params: {
                            employeeId:sessionStorage.getItem("employeeId")
                        },
                        onSuccess: function (data) {
                            var data = eval('(' + data + ')');
                            if (data.code == 1) {
                                infoVm.EmployeeDetail=data.data;
                                infoVm.telephone=data.data.telephone;
                                infoVm.email=data.data.email;
                                infoVm.idCard=data.data.idCard;
                            } else{
                                Ewin.alert("查询错误！");
                            }
                        }
                    };
                    ajaxHelper().apiReq(config);
                }else{
                    Ewin.alert('登录过期，请重新登录！').on(function(){
                        sessionStorage.clear();
                        window.location.href="login.html?"+(new Date()).getTime();
                    });
                }
            }else{
                Ewin.alert('未登录，请先登录！').on(function(){
                    window.location.href="login.html?"+(new Date()).getTime();
                });
            }
        },

        /**
         * 保存员工信息
         */
        save:function () {
            if(isLogin()){
                if(!isLoginLose()){
                    var config = {
                        url: httpURL + "el/employee/update",
                        params: {
                            employeeId:sessionStorage.getItem("employeeId"),
                            telephone:infoVm.telephone,
                            idCard:infoVm.idCard,
                            email:infoVm.email
                        },
                        onSuccess: function (data) {
                            var data = eval('(' + data + ')');
                            if (data.code == 1) {
                                Ewin.alert("更新成功!");
                                infoVm.GetEmployeeDetail();
                            } else if(data.code == 0){
                                Ewin.alert('登录过期，请重新登录！').on(function(){
                                    sessionStorage.clear();
                                    window.location.href="login.html?"+(new Date()).getTime();
                                });
                            }
                        }
                    };
                    ajaxHelper().apiReq(config);
                }else{
                    Ewin.alert('登录过期，请重新登录！').on(function(){
                        sessionStorage.clear();
                        window.location.href="login.html?"+(new Date()).getTime();
                    });
                }
            }else{
                Ewin.alert('未登录，请先登录！').on(function(){
                    window.location.href="login.html?"+(new Date()).getTime();
                });
            }
        }
    }
});
$(function () {
    infoVm.GetEmployeeDetail();
});